//
//  HHHttpConfig.m
//  BCBaseNetworking
//
//  Created by Basic on 15/3/19.
//  Copyright (c) 2015年 Basic. All rights reserved.
//

#import "HHHttpConfig.h"
#import "HHNetworkKitHeader.h"
#import "BCHttpRequestModel.h"
#import "BCHttpResponseModel.h"

@implementation HHHttpConfig

#pragma mark - HHHttpConfigProtocol
- (void)hhnet_setup:(HHHttpConfig *)config {
    if ([self.configDelegate respondsToSelector:@selector(hhnet_setup:)]) {
        [self.configDelegate hhnet_setup:config];
    }
}
-(void)hhnet_willSendRequest:(BCHttpRequestModel *)request {
    ////////构造 post 参数////////
    if(!request.headerParams){
        request.headerParams = [[NSMutableDictionary alloc] initWithCapacity:0];;
    }
    request.isLoadingMore = [request.customPost[kZHNetwork_IsLoadingMore] boolValue];
    
    //移除不需要的参数
    if (request.customPost.count>0) {
        [request.serverPostParams addEntriesFromDictionary:request.customPost];
        [request.serverPostParams removeObjectForKey:kZHNetwork_ShowLoading];
        [request.serverPostParams removeObjectForKey:kZHNetwork_LoadingMsg];
        [request.serverPostParams removeObjectForKey:kZHNetwork_HideErrorMsg];
        [request.serverPostParams removeObjectForKey:kZHNetwork_HideErrorMsgCodes];
        [request.serverPostParams removeObjectForKey:kZHNetwork_ShowErrorStyle];
        [request.serverPostParams removeObjectForKey:kZHNetwork_DefaultErrMsg];
        [request.serverPostParams removeObjectForKey:kZHNetwork_SuccessMsg];
        [request.serverPostParams removeObjectForKey:kZHNetwork_IsLoadingMore];
        [request.serverPostParams removeObjectForKey:kZHNetwork_NoSaveLog];
        [request.serverPostParams removeObjectForKey:kZHNetwork_AlertCancelText];
        
        [request.serverPostParams removeObjectForKey:kZHNetwork_DisableUser];
        [request.serverPostParams removeObjectForKey:kZHNetwork_InsideData];
        [request.serverPostParams removeObjectForKey:kZHNetwork_UserAuth];

    }
    
    request.finalURL = request.requestURL;
    if ([self.configDelegate respondsToSelector:@selector(hhnet_willSendRequest:)]) {
        [self.configDelegate hhnet_willSendRequest:request];
    }
}
- (void)hhnet_onRequestComplate:(BCHttpRequestModel *)request response:(BCHttpResponseModel *)response {
    if ([self.configDelegate respondsToSelector:@selector(hhnet_onRequestComplate:response:)]) {
        //新版本回调
        [self.configDelegate hhnet_onRequestComplate:request response:response];
    }
}
-(void)hhnet_showLoading:(NSString *)msg {
    if ([self.configDelegate respondsToSelector:@selector(hhnet_showLoading:)]) {
        [self.configDelegate hhnet_showLoading:msg];
    }else {
        NSLog(@"未指定指示器");
    }
}
- (void)hhnet_showSuccessMsg:(NSString *)msg {
    if ([self.configDelegate respondsToSelector:@selector(hhnet_showSuccessMsg:)]) {
        [self.configDelegate hhnet_showSuccessMsg:msg];
    }else {
        NSLog(@"未指定指示器");
    }
}
-(void)hhnet_hideLoading {
    if ([self.configDelegate respondsToSelector:@selector(hhnet_hideLoading)]) {
        [self.configDelegate hhnet_hideLoading];
    }else {
        NSLog(@"未指定指示器");
    }
}
- (void)hhnet_handleErrorMsg:(BCHttpResponseModel *)response {
    if ([self.configDelegate respondsToSelector:@selector(hhnet_handleErrorMsg:)]) {
        [self.configDelegate hhnet_handleErrorMsg:response];
    }else {
        NSLog(@"未指定指示器");
    }
}
@end
